App.require(function () {
    var app = App.getCurrent();
    app.definePage("strpcselectYear", {
        render: function (next) {
            var data = this.data, parentData = this.parent.data;
            data.yDate = parentData.yDate;
            data.minDate = parentData.minDate;
            data.maxDate = parentData.maxDate;
            var obj = this.createLisHtml(data.yDate.year, 1950, 2200);
            this.data.lisHTML = obj.html;
            this.data.offset = obj.index;
            this.fetch("./index.html", function (text) {
                next(this.renderHTML(text));
            })
        },
        init: function () {
            var scrollTop = (this.data.offset - 3.5) * 36 ;
            this.domList.selectYear.scrollTop = scrollTop > 0 ? scrollTop : 0;
        },
        getDomObj: function () {
            this.attachDom(".pc-year-container", "selectYear")
                .attachEvent("selectYear", "click", this.selectYearHandler, false);
        },
        createLisHtml: function (cYear, fYear, lYear) {
            var html = "";
            for (var i = fYear; i < lYear; i++) {
                var className = [];
                if (i == cYear) className.push("current");
                if (this.data.minDate && this.data.minDate.year > i) className.push("disabled-item");
                if (this.data.maxDate && this.data.maxDate.year < i) className.push("disabled-item");
                html += '<li class="' + className.join(" ") + '">' + i + '</li>';
            }
            return {
                html: html,
                index: parseInt((cYear - fYear) / 3)
            };
        },
        selectYearHandler: function (ev) {
            var target = ev.target;
            if (target.nodeName.toUpperCase() === "LI" && !target.classList.contains("disabled-item")) {
                var year = parseInt(target.textContent);
                this.parent.staticPage.changeYearToIndex(year);
            }
        },
    })
})